package org.sunrise.game.common.network.start;

import org.sunrise.game.common.network.client.BaseClientManager;
import org.sunrise.game.common.network.message.BaseMessage;
import org.sunrise.game.common.network.server.BaseServerManager;
import org.sunrise.game.common.utils.Utils;

public class MixtureStartUp {
    public static void main(String[] args) throws InterruptedException {
        var server1 = BaseServerManager.createBaseServer("server-node1");
        server1.startListen(Utils.getLocalIpAddress(), 1000);

        var client1 = BaseClientManager.createBaseClient("client-node1");
        client1.connectBlock(Utils.getLocalIpAddress(), 1000);

        var client2 = BaseClientManager.createBaseClient("client-node2");
        client2.connectBlock(Utils.getLocalIpAddress(), 1000);

        for (int i = 0; i < 1; i++) {
            var message = new BaseMessage();
            message.setMsg(i);
            client1.sendToServer(message);
        }
        for (int i = 2; i < 4; i++) {
            var message = new BaseMessage(client2.getNodeId());
            message.setMsg(i);
            BaseClientManager.sendMsgToServer(message);
        }

        var sendMsg = new BaseMessage("", client1.getNodeId(), 0, 100);
        var sendMsg1 = new BaseMessage(server1.getNodeId(), client1.getNodeId(), 0, 100);
        var sendMsg2 = new BaseMessage(server1.getNodeId(), client2.getNodeId(), 0, 200);
        var sendMsg3 = new BaseMessage(server1.getNodeId(), client2.getNodeId(), 0, 300);
        server1.sendToClient(sendMsg);
        server1.sendToClient(sendMsg1);
        server1.sendToClient(sendMsg2);
        BaseServerManager.sendMsgToClient(sendMsg3);
    }
}
